import os


def GetSize(path, size=0):
    fileList = os.listdir(path)
    for v in fileList:
        v = os.path.join(path, v)
        if os.path.isdir(v):
            # if path == "." or path == "..":
            #     continue
            # else:
                size = GetSize(v, size)
        # elif os.path.isfile(v):
        #     size += os.path.getsize(v)
        else:
            size += os.path.getsize(v)
    return size


def traverse(path):
    db = 0
    # 拿到p路径下所有文件和文件夹的名字
    fs = os.listdir(path)
    for f1 in fs:
        # 拼接路径和文件夹的名字，合成一个绝对路径
        next_path = os.path.join(path, f1)
        if not os.path.isdir(next_path):
            db += os.path.getsize(next_path)
        else:
            ret = traverse(next_path)  # 每调用一次会返回一个db
            db += ret
    return db


if __name__ == "__main__":
    path = os.path.abspath("/data/home/ylf/hudi/scripts")
    size = GetSize(path)
    print(size)
